package com.example.myrecipes;

import java.util.ArrayList;
import java.util.Iterator;

import android.os.Parcel;
import android.os.Parcelable;

public class RecipeBox implements Parcelable {
	private String recipeBoxName;
	private ArrayList<Recipe> recipeList;

	public RecipeBox(String recipeBoxName) {
		this.setRecipeBoxName(recipeBoxName);
		recipeList = new ArrayList<Recipe>();
		Recipe bananaCupcake = new Recipe("Banana Cupcake");
		Recipe waffles = new Recipe("Waffles");
		waffles.addInstructions("Mix flour and baking soda");
		waffles.addInstructions("Mix one egg at a time");
		waffles.addIngredient("flour");
		waffles.setCookTime("30 mins");
		waffles.setPrepTime("5 mins");
		waffles.setYield("21 waffles (10 servings)");
		waffles.setReadyInTime("26 mins");
		recipeList.add(bananaCupcake);
		recipeList.add(waffles);
	}

	public RecipeBox(Parcel in) {
		recipeBoxName = in.readString();
		recipeList = new ArrayList<Recipe>();
		in.readList(recipeList, getClass().getClassLoader());
	}

	public ArrayList<Recipe> getRecipeList() {
		return recipeList;
	}

	public void editRecipeBoxName(String newRecipeBoxName) {
		setRecipeBoxName(newRecipeBoxName);
	}
	public void addRecipe(Recipe recipe) {
		recipeList.add(recipe);
	}

	public void deleteRecipe(Recipe recipe) {
		Iterator<Recipe> it = recipeList.iterator();
		while (it.hasNext()) {
			Recipe curRecipe = it.next();
			if (curRecipe.equals(recipe)) {
				it.remove();
			}
		}
	}

	public String getRecipeBoxName() {
		return recipeBoxName;
	}

	public void setRecipeBoxName(String recipeBoxName) {
		this.recipeBoxName = recipeBoxName;
	}

	@Override
	public String toString() {
		return recipeBoxName;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(recipeBoxName);
		dest.writeList(recipeList);
	}

	public static final Parcelable.Creator<RecipeBox> CREATOR = new Parcelable.Creator<RecipeBox>() {		
		@Override
		public RecipeBox createFromParcel(Parcel source) {
			return new RecipeBox(source);
		}
		public RecipeBox[] newArray(int size) {
			return new RecipeBox[size];
		}
	};

}
